<%@ page import="sy.pageModel.BaseEntity" %>
<%@ page import="sy.pageModel.Member" %>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<script type="text/javascript">
    var editor = new baidu.editor.ui.Editor();
    $(function() {
//        显示查询信息（含分页、排序、筛选等功能）
        $('#admin_activity_datagrid').datagrid({
            url : '${pageContext.request.contextPath}/activityController/datagrid.action',
            fit : true, fitColumns : true, border : false, pagination : true,
            idField : 'id', pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50 ], sortName : 'isShow', sortOrder : 'desc',
            checkOnSelect : false, selectOnCheck : false, nowrap : false,
            frozenColumns : [ [ {  field : 'id',title : '编号',checkbox : true}]],
            columns:[[{
                field : 'day',title : '卡有效期（天）'},{
                field : 'createTimeStart',title : '开始时间'},{
                field : 'createTimeEnd',title : '结束时间'},{
                field : 'showName',title : '是否启用' ,align : 'center',formatter: function (value) {
                    if (value=="是") return formatString('<span style="color: green;font-weight: 800">已启用</span>');
                    else return formatString('<span style="color: red;font-weight: 800">已禁用</span>' );
                }},{
                field : 'text',title : '创建时间',},{
                field : 'isShow',title : '操作(是否启用)',align : 'center',
                formatter : function(value, row, index) {
                    if (value=="N")return formatString('<input type="button" value=" 启 用 " style="font-weight: 800; border-radius: 2px;color: green" onclick="admin_activity_editFun(\'{0}\')">',row.id);
                    else   return formatString('');
                }}
            ]],
            toolbar : [ {
                text : '添加内容',iconCls : 'icon-add',handler : function() {
                    admin_activity_appendFun();
                }
            }]
        });
    });

    function admin_activity_searchFun() {
        $('#admin_activity_datagrid').datagrid('load', serializeObject($('#admin_activity_searchForm')));
    }

    function admin_activity_cleanFun() {
        $('#admin_activity_searchForm input').val('');
        $('#admin_activity_datagrid').datagrid('load', {});
    }
    function admin_activity_appendFun() {
        $('#admin_activity_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $('<div/>').dialog({
            href : '${pageContext.request.contextPath}/admin/activity_add.jsp',
            width : 800,
            height :600,
            modal : true,
            title : '信息添加',
            buttons : [ {
                text : '保存',
                iconCls : 'icon-add',
                handler : function() {
                    var d = $(this).closest('.window-body');
                    $('#admin_activityAdd_addForm').form('submit', {
                        url : '${pageContext.request.contextPath}/activityController/add_currency.action',
                        success : function(result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.success) {
                                    $('#admin_activity_datagrid').datagrid('load',{sort : 'isShow', order : 'desc'});
                                    d.dialog('destroy');
                                }
                                $.messager.show({
                                    title : '提示',
                                    msg : r.msg
                                });
                            } catch (e) {
                                $.messager.alert('提示', result);
                            }
                        }
                    });
                }
            } ],
            onClose : function() {
                $(this).dialog('destroy');
            }
        });
    }
    function admin_activity_editFun(id){
        $.post("${pageContext.request.contextPath}/activityController/edit_currency.action",{id:id}, function (result) {
            try {
                var r = $.parseJSON(result);
                if (r.success) $('#admin_activity_datagrid').datagrid('load',{sort : 'isShow', order : 'desc'});
                $.messager.show({
                    title : '提示', msg : r.msg
                });
            } catch (e) {
                $.messager.alert('提示', result);
            }
        })
    }
</script>
<div class="easyui-layout" data-options="fit : true,border : false">
    <div data-options="region:'center',border:false">
        <table id="admin_activity_datagrid"></table>
    </div>
</div>
